package main

import (
	"embed"
	"io/fs"
	"net/http"

	"github.com/gin-gonic/gin"
)

// 使用embed指令嵌入静态资源
//go:embed static/*
var StaticFS embed.FS

//go:embed images/*
var ImagesFS embed.FS

// SetupStaticRoutes 设置静态资源路由
func SetupStaticRoutes(router *gin.Engine) {
	// 设置static目录
	staticSub, err := fs.Sub(StaticFS, "static")
	if err != nil {
		panic(err)
	}
	router.StaticFS("/static", http.FS(staticSub))
	
	// 设置images目录
	imagesSub, err := fs.Sub(ImagesFS, "images")
	if err != nil {
		panic(err)
	}
	router.StaticFS("/images", http.FS(imagesSub))
	
	// 设置favicon.ico
	faviconData, err := ImagesFS.ReadFile("favicon.ico")
	if err == nil {
		router.GET("/favicon.ico", func(c *gin.Context) {
			c.Data(http.StatusOK, "image/x-icon", faviconData)
		})
	}
}
